#include <iostream>
#include <string>
using namespace std;

class IQuery 
{
public:
	virtual ~IQuery() {}
	virtual string getSelect()=0;
	virtual void setSelect(string select)=0;
	virtual void query()=0;
	virtual IQuery* clone()=0;
};

class GenericQuery: public IQuery 
{
private:
	string select;
public:
	string getSelect() 
	{
		return this->select;
	}
	void setSelect(string select) 
	{
		this->select = select;
	}
	void query() 
	{
		cout << "execute the sql: " << select << "from ..." << endl;
	}
	GenericQuery* clone() 
	{
		return new GenericQuery(*this);
	}
};

class QuerySupport 
{
public:
	void getCount(IQuery* iQuery) 
	{
		cout << ">>> call getCount()" << endl;
		IQuery* clone = iQuery->clone();
		//iQuery->setSelect("select count(*) ");
		//iQuery->query();
		clone->setSelect("select count(*) ");
		clone->query();
	}
	void query(IQuery* iQuery) 
	{
		cout << ">>> call query()" << endl;
		iQuery->query();
	}
};

int main() 
{
	IQuery* iQuery = new GenericQuery();
	iQuery->setSelect("select * ");

	QuerySupport* support = new QuerySupport();
	support->getCount(iQuery);
	support->query(iQuery);
	return 0;
}
